<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/home/include/init_home.jsp" %>
<%@ page import="com.qbooks.home.store.*" %>
<%
	String book_code		= StringUtil.nvl(request.getParameter("book_code"));


	StoreDAO dao 			= new StoreDAO();
	

	HashMap param 			= new HashMap();
	param.put("book_code",	book_code);


	HashList info 			= dao.selectBookInfo(param);
	HashList reviewList		= dao.selectBookReviewList(param);
	
	param.put("category_code", info.get("category_code",0));
	HashList categoryInfo	= dao.selectCategoryInfo(param);

	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi" >
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link rel="stylesheet" href="/css/mobile.css" />
	<title><%= HOME_NAME %></title>

	<script type="text/javascript">

	$(document).ready(function() {
		$('span.rate').mouseover(function(){
			var curTitle = $(this).attr('title');
			$('span.rate').each(function(){
				if ($(this).attr('title') <= curTitle) {
					$(this).text('★');
				} else {
					$(this).text('☆');
				}
			});
		})

	});


	function btnPuchase() {
		$('#saveForm').attr('action', './bookPurchase.do');
		$('#saveForm').submit();
	}

	
	function btnReviewSave() 
	{
		var intRate = 0;
		$('span.rate').each(function(){
			if ($(this).text() == '★') {
				if ($(this).attr('title') > intRate) {
					intRate = $(this).attr('title');
				}
			}
		});

		if (intRate == 0) {
			alert('평점을 선택하세요');
			return false;
		} 

		$.ajax({
			url: './reviewSave.do',
			type: "POST",
		    dataType: 'json',
		    data:{ 
		    	book_code:'<%=book_code%>',
		    	rate:intRate, 
		    	review_info:$('#review_info').val() 
		    },
		    error: function(data, status, err){
		    	alert(err);
		    },
			success: function(data){
				if (data.result) {
					alert('성공');
				} else {
					alert(data.message);
				}
		    }
		});
	}
	
	function btnReviewCancel() {
		$("span.rate").text("☆");
		$("textarea[name='review_info']").text("");
		$("#review").hide();
	}

	</script>
</head>
<body>
<div id="wrap">
	<div id="main">
		<div >
			<div style="float:left; width:220px; min-height:220px;">
				<img src="<%= info.get("book_image_url",0) %>" width="200px"/>
			</div>
			<div style="margin-left:10px">
				<div>
					<b><h3><%= info.get("book_name", 0) %></h3></b>
					<%= info.get("sub_title",0) %>
				</div>
				<br/>
				<br/>
				<div><%= info.get("author_name",0) %> 저, <%= info.get("publisher_name",0) %>, <%= StringUtil.toDate(info.get("publish_dt",0),".") %></div>
				<div><%= StringUtil.toPrice(info.get("price",0)) %>원</div>
				<div><input type="button" name="purchase" alt="구매하기" value="구매하기"/></div>
			</div>
			<div style="clear:both; margin-top:20px">
				<div><h3>설명</h3></div>
				<hr></hr>
				<div><%= info.get("intro", 0) %></div>
			</div>
			<div style="clear:both; margin-top:20px">
				<div><h3>목차</h3></div>
				<hr></hr>
				<div><%= StringUtil.toHTML(info.get("index_info", 0)) %></div>
			</div>
			<div style="clear:both; margin-top:20px">
				<div><h3>저자 정보</h3></div>
				<hr></hr>
				<div><%= StringUtil.toHTML(info.get("author_info", 0)) %></div>
			</div>
			<div style="clear:both; margin-top:20px">
				<div>
					<h3 class="inline">리뷰</h3>
				<%	if (isLogin) { %>
						<a href="#nohref" onclick="$('#review').toggle()">리뷰작성</a>
				<%	} %>
				</div>
				<hr></hr>
				<div>
					<form name="reviewForm" id="reviewForm" method="post" action="./reviewSave.do">
					<div id="review" class="none">
						<table>
							<tr>
								<td width="100px">
									<%=session_user_name %>
								</td>
								<td>
									<textarea name="review_info" id="review_info" style="width:560px; height:80px"></textarea>
									<span class="rate" title="1">☆</span>
									<span class="rate" title="2">☆</span>
									<span class="rate" title="3">☆</span>
									<span class="rate" title="4">☆</span>
									<span class="rate" title="5">☆</span>
									<input type="button" value="리뷰등록" onclick="btnReviewSave()"/>
									<input type="button" value="취소" onclick="btnReviewCancel()"/>
								</td>
							</tr>
						</table>
					</div>
					</form>
				</div>
	<%		for (int i = 0; i < reviewList.size(); i++) { %>
				<div>
					<%= reviewList.get("member_name",i) %>[<%= reviewList.get("rate",i) %>]
					<%= reviewList.get("review_info",i) %>
					<%= reviewList.get("init_date",i) %>
				</div>
	<%		} %>
			</div>
		</div>
		  
	</div>
</div>
</body>
</html>
